﻿using System;
using System.Collections.Generic;

namespace QFramework.Fullstack
{
    public interface IFrameworkLayer
    {
        void Register<T>(object obj);
        T Get<T>() where T : class;
        void Clear();
    }
    
    public class FrameworkLayer : IFrameworkLayer
    {
        private Dictionary<Type, object> mContainer = new Dictionary<Type, object>();

        public void Register<T>(object obj)
        {
            var type = typeof(T);
            if (mContainer.ContainsKey(type))
            {
                mContainer[type] = obj;
            }
            else
            {
                mContainer.Add(type, obj);
            }
        }

        public T Get<T>() where T : class
        {
            return mContainer[typeof(T)] as T;
        }

        public void Clear()
        {
            mContainer.Clear();
        }
    }
}